export type TodoType = {
  id: number
  name: string
  isDone: boolean
}


const initValue: TodoType[] = [
  {
    id: 1,
    name: '吃饭',
    isDone: false,
  },
  {
    id: 2,
    name: '睡觉',
    isDone: true,
  },
  {
    id: 3,
    name: '打豆豆',
    isDone: false,
  },
]
export default function todos(state = initValue, action: any): TodoType[] {
  // 修改状态
  const id = action.payload

  if (action.type === 'UPDATE_STATE') {
    return state.map(item => {
      if (item.id === id) {
        return { ...item, isDone: !item.isDone }
      } else {
        return { ...item }
      }
    })
  }

  // 删除
  else if (action.type === 'DEL_TODO') {
    return state.filter(item => item.id !== id)
  }

  else if (action.type === 'add_TODO') {
    console.log(action.payload, 2323423);

    return [...state, action.payload]
  }




  return state
}
